package city.spring.controller.mealService;

import com.baomidou.mybatisplus.extension.api.ApiController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/recipes")
public class RecipesApiController extends ApiController {

//    private final RecipesService recipesService;
//    private final RecipesWeekService recipesWeekService;
//
//    private final List<SFunction<RecipesWeekEntity, ?>> entityOrderFields;
//
//    public RecipesApiController(RecipesService recipesService, RecipesWeekService recipesWeekService) {
//        this.recipesService = recipesService;
//        this.recipesWeekService = recipesWeekService;
//        this.entityOrderFields = new ArrayList<>();
//    }
//
//    @GetMapping("getAllRecipes")
//    public Object getAllType() {
//        List<RecipesEntity> recipesEntities = recipesService.list();
//        List<RecipesWeekEntity> valueEntities = recipesWeekService.list();
//
//        ArrayListMultimap<String, RecipesWeekEntity> multimap = ArrayListMultimap.create();
//        valueEntities.forEach(recipesWeekEntity -> multimap.put(recipesWeekEntity.getRecipesId(), recipesWeekEntity));
//        recipesEntities.forEach(recipesEntity ->
//                recipesEntity.setChildren(multimap.get(recipesEntity.getId())));
//
//
//        return success(recipesEntities);
//    }
//
//    @GetMapping("recipes-{recipesId}")
//    public Object listValues(@PageableDefault(sort = {"sorted", "gmtCreate"}) Pageable pageable, RecipesWeekEntity entity, @PathVariable String recipesId) {
//        return success(loadRecipesEntity(pageable, entity, recipesId).getChildren());
//    }
//
//    @NonNull
//    private RecipesEntity loadRecipesEntity(Pageable pageable, RecipesWeekEntity entity, String recipesId) {
//        RecipesEntity result;
//
//        List<RecipesEntity> recipesEntities = recipesService.lambdaQuery()
//                .eq(RecipesEntity::getRecipesCode, recipesId)
//                .or()
//                .eq(RecipesEntity::getId, recipesId)
//                .list();
//
//        // 判断查找结果是否为空
//        if (recipesEntities.isEmpty()) {
//            result = new RecipesEntity();
//            result.setRecipesName("未知食谱类型");
//            result.setChildren(Collections.emptyList());
//            return result;
//        }
//
//        // 查找食谱周次信息列表信息
//        LambdaQueryChainWrapper<RecipesWeekEntity> lambdaQuery = buildLambdaQuery(entity);
//        MyBatisUtils.lambdaQueryAddOrder(lambdaQuery, pageable, entityOrderFields);
//        if (recipesEntities.size() == 1) {
//            result = recipesEntities.get(0);
//            lambdaQuery.eq(RecipesWeekEntity::getRecipesId, result.getId());
//        } else {
//            result = recipesEntities.get(0);
//            List<String> stringList = recipesEntities.stream()
//                    .map(RecipesEntity::getId)
//                    .collect(Collectors.toList());
//            lambdaQuery.in(RecipesWeekEntity::getRecipesId, stringList);
//        }
//        result.setChildren(lambdaQuery.list());
//        return result;
//    }
//
//    @NonNull
//    private LambdaQueryChainWrapper<RecipesWeekEntity> buildLambdaQuery(RecipesWeekEntity entity) {
//        LambdaQueryChainWrapper<RecipesWeekEntity> lambdaQuery = recipesWeekService.lambdaQuery();
//        return lambdaQuery;
//    }

}
